package com.lamatek.tags.google;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

/**
 * GoogleMapClusterTag
 * 
 * This tag represents a &lt;googlemaps:cluster> tag and allows developers to groups
 * icons together into clusters, that expand as the user zooms in on them. Developers should
 * not extend this class or override it's methods.
 */
public class GoogleMapClusterTag extends BodyTagSupport {
    
    GoogleMapIconTag icon = null;
    int maxVisibleMarkers = 100;
    int gridSize = 5;
    int markersPerCluster = 5;
    String pathToScript = null;
    /**
     * Overrides doStartTag() from TagSupport. Developers should not override this method.
     */
    public int doStartTag() {
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapTag) {
                ((GoogleMapTag) tag.getParent()).setClusterer(this);
                return EVAL_BODY_INCLUDE;
            }
            tag = tag.getParent();
        }
        return EVAL_BODY_INCLUDE;
    }
    public int getGridSize() {
        return gridSize;
    }
    public void setGridSize(int gridSize) {
        this.gridSize = gridSize;
    }
    /**
     * Gets the GoogleMapIconTag that will render the icons for clustered markers.
     * 
     * @return A GoogleMapIconTag or null if not defined.
     */
    public GoogleMapIconTag getIcon() {
        return icon;
    }
    /**
     * Sets the GoogleMapIconTag that will render the icons for clustered markers.
     * 
     * @param icon A GoogleMapIconTag.
     */
    public void setIcon(GoogleMapIconTag icon) {
        this.icon = icon;
    }
    /**
     * Returns the minimum number of markers that can be joined to create a cluster.
     * 
     * @return Minimum markers per cluster.
     */
    public int getMarkersPerCluster() {
        return markersPerCluster;
    }
    /**
     * Sets the minimum number of markers that can be joined to create a cluster.
     * 
     * @param markersPerCluster Minimum markers per cluster.
     */
    public void setMarkersPerCluster(int markersPerCluster) {
        this.markersPerCluster = markersPerCluster;
    }
    /**
     * Returns the maximum number of visible markers (both clustered and non-clustered) that 
     * should appear on the map.
     * 
     * @return The maximum number of displayed markers.
     */
    public int getMaxVisibleMarkers() {
        return maxVisibleMarkers;
    }
    /**
     * Sets the maximum number of visible markers (both clustered and non-clustered) that 
     * should appear on the map.
     * 
     * @param maxVisibleMarkers The maximum number of displayed markers.
     */
    public void setMaxVisibleMarkers(int maxVisibleMarkers) {
        this.maxVisibleMarkers = maxVisibleMarkers;
    }
    /**
     *  Returns the path (URL) to the Clusterer.js file.
     * 
     * @return URL to javascript file.
     */
    public String getPathToScript() {
        return pathToScript;
    }
    /**
     * Sets the URL path to the Clusterer.js file. This must be a complete
     * relative or absolute URL, including filename.
     * 
     * @param pathToScript A valid URL that points to the Clusterer.js file.
     */
    public void setPathToScript(String pathToScript) {
        this.pathToScript = pathToScript;
    }
}
